import React, { useEffect, useState } from "react";
import { Descriptions, Button, Card, message } from "antd";
import { useNavigate, useParams } from "react-router-dom";
// 获取api请求
import { HospitalDetailsRequest } from "@/api/hospital/hospitalList";
// 引入限制
import { HospitalDetailsReturnType } from "@/api/hospital/model/hospitalListTypes";
export default function HospitalShow() {
  // 获取id 通过params传参
  const { id } = useParams();
  const Navigate = useNavigate();
  const [hosData, setHosData] = useState<HospitalDetailsReturnType>({});
  // 初始时请求数据
  useEffect(() => {
    const res = async () => {
      const re = await HospitalDetailsRequest(id as string);
      setHosData(re);
      message.success("加载成功");
    };
    res();
  }, []);
  return (
    <div>
      <Card>
        <Descriptions title="基本信息" bordered column={2}>
          <Descriptions.Item label="医院名称">
            {hosData.hospital?.hosname}
          </Descriptions.Item>
          <Descriptions.Item label="医院logo">
            {hosData.hospital?.logoData ? (
              <img
                width={100}
                src={`data:image/jpeg;base64,${hosData.hospital?.logoData}`}
                alt=""
              />
            ) : (
              ""
            )}
          </Descriptions.Item>
          <Descriptions.Item label="医院编码">
            {hosData.hospital?.hoscode}
          </Descriptions.Item>
          <Descriptions.Item label="医院地址">
            {hosData.hospital?.param.fullAddress}
          </Descriptions.Item>
          <Descriptions.Item label="坐车路线" span={2}>
            {hosData.hospital?.route}
          </Descriptions.Item>
          <Descriptions.Item label="医院简介" span={2}>
            {hosData.hospital?.intro}
          </Descriptions.Item>
        </Descriptions>
        <Descriptions
          title="预约规则信息"
          bordered
          column={2}
          style={{ marginTop: "20px" }}
        >
          <Descriptions.Item label="预约周期">
            {hosData.bookingRule?.cycle}
          </Descriptions.Item>
          <Descriptions.Item label="放号时间">
            {hosData.bookingRule?.releaseTime}
          </Descriptions.Item>
          <Descriptions.Item label="停挂时间">
            {hosData.bookingRule?.stopTime}
          </Descriptions.Item>
          <Descriptions.Item label="退号时间">
            {hosData.bookingRule?.quitTime}
          </Descriptions.Item>
          <Descriptions.Item label="预约规则" span={2}>
            {hosData.bookingRule?.rule.map((item, index) => (
              <p key={index}>{item}</p>
            ))}
          </Descriptions.Item>
        </Descriptions>
        <Button onClick={() => Navigate(-1)} style={{ marginTop: "20px" }}>
          返回
        </Button>
      </Card>
    </div>
  );
}
